import 'package:nyh_motorcade_app/entity/card_info_entity.dart';

cardInfoEntityFromJson(CardInfoEntity data, Map<String, dynamic> json) {
	if (json['page'] != null) {
		data.page = json['page'] is String
				? int.tryParse(json['page'])
				: json['page'].toInt();
	}
	if (json['pageSize'] != null) {
		data.pageSize = json['pageSize'] is String
				? int.tryParse(json['pageSize'])
				: json['pageSize'].toInt();
	}
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['totalPage'] != null) {
		data.totalPage = json['totalPage'] is String
				? int.tryParse(json['totalPage'])
				: json['totalPage'].toInt();
	}
	if (json['item'] != null) {
		data.item = (json['item'] as List).map((v) => CardInfoItem().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> cardInfoEntityToJson(CardInfoEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['page'] = entity.page;
	data['pageSize'] = entity.pageSize;
	data['total'] = entity.total;
	data['totalPage'] = entity.totalPage;
	data['item'] =  entity.item?.map((v) => v.toJson())?.toList();
	return data;
}

cardInfoItemFromJson(CardInfoItem data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'].toString();
	}
	if (json['serialNumber'] != null) {
		data.serialNumber = json['serialNumber'].toString();
	}
	if (json['cardNumber'] != null) {
		data.cardNumber = json['cardNumber'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['cardTypeName'] != null) {
		data.cardTypeName = json['cardTypeName'].toString();
	}
	if (json['energyTypeName'] != null) {
		data.energyTypeName = json['energyTypeName'].toString();
	}
	if (json['cardBalance'] != null) {
		data.cardBalance = json['cardBalance'] is String
				? double.tryParse(json['cardBalance'])
				: json['cardBalance'].toDouble();
	}
	if (json['driverInfo'] != null) {
		data.driverInfo = json['driverInfo'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'] is String
				? int.tryParse(json['status'])
				: json['status'].toInt();
	}
	if (json['remark'] != null) {
		data.remark = json['remark'].toString();
	}
	if (json['cardType'] != null) {
		data.cardType = json['cardType'].toString();
	}
	if (json['energyType'] != null) {
		data.energyType = json['energyType'].toString();
	}
	if (json['isSelect'] != null) {
		data.isSelect = json['isSelect'];
	}
	if (json['availableAmount'] != null) {
		data.availableAmount = json['availableAmount'] is String
				? double.tryParse(json['availableAmount'])
				: json['availableAmount'].toDouble();
	}
	return data;
}

Map<String, dynamic> cardInfoItemToJson(CardInfoItem entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['serialNumber'] = entity.serialNumber;
	data['cardNumber'] = entity.cardNumber;
	data['name'] = entity.name;
	data['cardTypeName'] = entity.cardTypeName;
	data['energyTypeName'] = entity.energyTypeName;
	data['cardBalance'] = entity.cardBalance;
	data['driverInfo'] = entity.driverInfo;
	data['status'] = entity.status;
	data['remark'] = entity.remark;
	data['cardType'] = entity.cardType;
	data['energyType'] = entity.energyType;
	data['isSelect'] = entity.isSelect;
	data['availableAmount'] = entity.availableAmount;
	return data;
}